package com.kdg.thread.consurrenttest;

import java.util.Random;
import java.util.concurrent.*;

/**
 * @author kdg
 * @description:
 * @date 2018/5/13.
 */
public class CountDownLatchTest implements Runnable{
    static final CountDownLatch end = new CountDownLatch(10);
    static final CountDownLatchTest demo = new CountDownLatchTest();

    @Override
    public void run() {
        try {
            Thread.sleep((new Random()).nextInt(10)*1000);
            System.out.println("check complete");
            end.countDown();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 10, 0L,
                TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
        for(int i=0;i<20;i++){
            threadPoolExecutor.submit(demo);
        }
        end.await();
        System.out.println("Fire");
        threadPoolExecutor.shutdown();
    }
}
